package com.gpc.hexapods.data;


import com.gpc.hexapods.utils.MathUtil;

public class Leg3Data {

    public static final float LENGTH = Cons.L3;
    public static final float WIDTH = 0.06f;
    public static final float HEIGHT = 0.12f;

    public Point point3;
    public Point point4;
    public float aAngle;
    public float bAngle;
    public float cAngle;

    public float[] position;
    public short[] index;
    public float[] color;

    public Leg3Data(Point point3, Point point4, float aAngle, float bAngle, float cAngle) {
        this.point3 = point3;
        this.point4 = point4;
        this.aAngle = aAngle;
        this.bAngle = bAngle;
        this.cAngle = 180 - bAngle - cAngle;
        this.position = getPosition(point3, point4, aAngle, bAngle, cAngle);
        initData();
    }

    public float[] getPosition(Point point3, Point point4, float aAngle, float bAngle, float cAngle) {
        return new float[]{
                //正面左上0
                point3.x - HEIGHT * MathUtil.cos(aAngle) * MathUtil.sin(cAngle) - WIDTH * MathUtil.sin(aAngle),
                point3.y - HEIGHT * MathUtil.sin(aAngle) * MathUtil.sin(cAngle) + WIDTH * MathUtil.cos(aAngle),
                point3.z - HEIGHT * MathUtil.cos(cAngle),

                //正面左下1
                point3.x - HEIGHT * MathUtil.cos(aAngle) * MathUtil.sin(cAngle) + WIDTH * MathUtil.sin(aAngle),
                point3.y - HEIGHT * MathUtil.sin(aAngle) * MathUtil.sin(cAngle) - WIDTH * MathUtil.cos(aAngle),
                point3.z - HEIGHT * MathUtil.cos(cAngle),

                //正面右下2
                point4.x - HEIGHT * MathUtil.cos(aAngle) * MathUtil.sin(cAngle) + WIDTH * MathUtil.sin(aAngle),
                point4.y - HEIGHT * MathUtil.sin(aAngle) * MathUtil.sin(cAngle) - WIDTH * MathUtil.cos(aAngle),
                point4.z - HEIGHT * MathUtil.cos(cAngle),

                //正面右上3
                point4.x - HEIGHT * MathUtil.cos(aAngle) * MathUtil.sin(cAngle) - WIDTH * MathUtil.sin(aAngle),
                point4.y - HEIGHT * MathUtil.sin(aAngle) * MathUtil.sin(cAngle) + WIDTH * MathUtil.cos(aAngle),
                point4.z - HEIGHT * MathUtil.cos(cAngle),

                //反面左上4
                point3.x + HEIGHT * MathUtil.cos(aAngle) * MathUtil.sin(cAngle) - WIDTH * MathUtil.sin(aAngle),
                point3.y + HEIGHT * MathUtil.sin(aAngle) * MathUtil.sin(cAngle) + WIDTH * MathUtil.cos(aAngle),
                point3.z + HEIGHT * MathUtil.cos(cAngle),

                //反面左下5
                point3.x + HEIGHT * MathUtil.cos(aAngle) * MathUtil.sin(cAngle) + WIDTH * MathUtil.sin(aAngle),
                point3.y + HEIGHT * MathUtil.sin(aAngle) * MathUtil.sin(cAngle) - WIDTH * MathUtil.cos(aAngle),
                point3.z + HEIGHT * MathUtil.cos(cAngle),

                //反面右下6
                point4.x + HEIGHT * MathUtil.cos(aAngle) * MathUtil.sin(cAngle) + WIDTH * MathUtil.sin(aAngle),
                point4.y + HEIGHT * MathUtil.sin(aAngle) * MathUtil.sin(cAngle) - WIDTH * MathUtil.cos(aAngle),
                point4.z + HEIGHT * MathUtil.cos(cAngle),

                //反面右上7
                point4.x + HEIGHT * MathUtil.cos(aAngle) * MathUtil.sin(cAngle) - WIDTH * MathUtil.sin(aAngle),
                point4.y + HEIGHT * MathUtil.sin(aAngle) * MathUtil.sin(cAngle) + WIDTH * MathUtil.cos(aAngle),
                point4.z + HEIGHT * MathUtil.cos(cAngle),
        };
    }

    public void initData() {
        index = new short[]{
                0, 3, 2, 0, 2, 1,    //正面
                0, 1, 5, 0, 5, 4,    //左面
                0, 7, 3, 0, 4, 7,    //上面
                6, 7, 4, 6, 4, 5,    //后面
                6, 3, 7, 6, 2, 3,    //右面
                6, 5, 1, 6, 1, 2     //下面
        };

        color = new float[]{
                0.5f, 0.5f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.5f, 0.5f, 1.0f,
                0.5f, 0.5f, 1.0f, 1.0f, 0.0f, 0.5f, 1.0f, 1.0f, 0.0f, 0.5f, 1.0f, 1.0f,

                0.5f, 0.5f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.5f, 0.5f, 1.0f,
                0.5f, 0.5f, 1.0f, 1.0f, 0.0f, 0.5f, 1.0f, 1.0f, 0.0f, 0.5f, 1.0f, 1.0f,

                0.5f, 0.5f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.5f, 0.5f, 1.0f,
                0.5f, 0.5f, 1.0f, 1.0f, 0.0f, 0.5f, 1.0f, 1.0f, 0.0f, 0.5f, 1.0f, 1.0f,

                0.5f, 0.5f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.5f, 0.5f, 1.0f,
                0.5f, 0.5f, 1.0f, 1.0f, 0.0f, 0.5f, 1.0f, 1.0f, 0.0f, 0.5f, 1.0f, 1.0f,
        };
    }
}
